//
//  Singleton.m
//  Day_9 UITableView
//
//  Created by dllo on 15/10/21.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "Singleton.h"
#import "Student.h"
@implementation Singleton

+(instancetype)shareSingleton{

    static Singleton *singleton = nil;
    if (singleton == nil) {
        singleton = [[Singleton alloc]init];
        //self在+方法里代表当前的类
        [singleton createStudentDic];
    }
    return singleton;
}

- (void)createStudentDic{
    NSMutableDictionary *dic1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"张智超", @"name", @"男", @"sex", nil];
    NSMutableDictionary *dic2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"张婷", @"name", @"女", @"sex", nil];
    NSMutableArray *zArray = [NSMutableArray arrayWithObjects:dic1, dic2, nil];
    
    NSMutableDictionary *dic3 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"王鑫", @"name", @"男", @"sex", nil];
    NSMutableDictionary *dic4 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"王雪飞", @"name", @"女", @"sex", nil];
    NSMutableArray *wArray = [NSMutableArray arrayWithObjects:dic3, dic4, nil];
    
    //最外层大字典
    NSMutableDictionary *bigDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:zArray, @"Z", wArray, @"W", nil];
    NSLog(@"%@", bigDic);
    
    //model
    
    //将大字典扒开,取到小字典里的学生信息,并赋值给model对象
    
    //创建最外层大字典
    self.studentDic = [NSMutableDictionary dictionary];
    
    for (NSString *key in bigDic) {
        //根据key取出对应的数组
        NSMutableArray *array = [bigDic objectForKey:key];
        
        //创建一个新的数组,存储model对象
        NSMutableArray *stuArray = [NSMutableArray array];
        
        for (NSMutableDictionary *dic in array) {
            //一个Student对象对应一个学生小字典
            Student *stu = [[Student alloc]init];
            stu.name = [dic objectForKey:@"name"];
            stu.sex = [dic objectForKey:@"sex"];
            
            //将model对象存入数组中
            [stuArray addObject:stu];
            [stu release];
            
        }
    
        //大字典赋值
        [self.studentDic setObject:stuArray forKey:key];
    
    
    
    
        
    }
    
}

@end
